package com.aftersale.demo.controller;

import com.aftersale.demo.entity.*;
import com.aftersale.demo.service.FaqService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * @author 空
 * @date 2023/11/27 18:25
 * @desc
 */
@RestController
@RequestMapping("/faq")
public class FaqController {

    @Autowired
    FaqService faqService;

    @GetMapping("/getfaq")
    @ApiOperation(value = "知识库查看接口")
    @PreAuthorize("hasAuthority('faq_select')")
    public Result getFaq(@RequestParam Integer pageNum,
                            @RequestParam Integer pageSize){
        return faqService.getFaq(pageNum,pageSize);
    }

    @GetMapping("/selectfaq")
    @ApiOperation(value = "知识库查询接口")
    @PreAuthorize("hasAuthority('faq_select')")
    public Result getFaq(@RequestParam Integer pageNum,
                            @RequestParam Integer pageSize,
                            @RequestParam String title){
        return faqService.selectFaq(pageNum,pageSize,title);
    }

    @DbLog(operation = "知识库",type = LogType.ADD)
    @PostMapping("/addfaq")
    @PreAuthorize("hasAuthority('faq_create')")
    @ApiOperation(value = "知识库添加接口")
    public Result addFaq(@RequestBody @Validated Faq faq){
        return faqService.addFaq(faq);
    }

    @DbLog(operation = "知识库",type = LogType.DELETE)
    @DeleteMapping("/deletefaq")
    @PreAuthorize("hasAuthority('faq_delete')")
    @ApiOperation(value = "公告删除接口")
    public Result deleteFaq(@RequestParam int id){
        return faqService.deleteFaq(id);
    }

    @DbLog(operation = "知识库",type = LogType.UPDATE)
    @PutMapping("/updatefaq")
    @PreAuthorize("hasAuthority('faq_update')")
    @ApiOperation(value = "知识库修改接口")
    public Result updateFaq(@RequestBody @Validated Faq faq){
        return faqService.updateFaq(faq);
    }
}
